package ymy;

import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @author com.ymy.hadoop
 * @date 2018/12/15 14:06
 */
public class MethodApp {

    @Test
    public void test01() throws Exception{
        Class<?>clazz = Class.forName("ymy.Student");
        Method[] methods = clazz.getMethods();
        for (Method method:methods){
            // System.out.println(method.getName());
           Class<?>[] parameterTypes = method.getParameterTypes();
           for(Class<?> parameterType : parameterTypes){
               System.out.println(method.getName() + ".." + parameterType);
           }
        }
    }
    @Test
    public void test02() throws Exception{
        Class<?> clazz = Class.forName("ymy.Student");
        Object object = clazz.newInstance();

        Method setMethod = clazz.getDeclaredMethod("setSex",String.class);
        setMethod.invoke(object,"男");

        Method getMethod = clazz.getDeclaredMethod("getSex");
        Object sex = getMethod.invoke(object);

        // System.out.println(object);
        System.out.println(sex);
    }
}
